package com.zhao.controller;

import com.zhao.pojo.Admin;
import com.zhao.pojo.SchoolCounsellor;
import com.zhao.service.OrderFormService;
import com.zhao.service.TradeRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class TradeRecordsController {

    @Autowired
    private TradeRecordsService tradeRecordsService;

    @Autowired
    private OrderFormService orderFormService;

    @RequestMapping("schoolCounsellor-getAllTR.do")
    public String schoolCounsellorGetAllTR(HttpSession session){

        SchoolCounsellor schoolCounsellor = (SchoolCounsellor) session.getAttribute("schoolCounsellor");
        if(schoolCounsellor==null)return "redirect:/";

        String res = tradeRecordsService.schoolCounsellorGetAll(schoolCounsellor,session);
        System.out.println("res-schoolCounsellorGetAllTR: "+res);
        if(!res.equals("success")){
            return "404";
        }

        return "redirect:/schoolCounsellor-seeAllTR";
    }

    @RequestMapping("admin-getAllTR.do")
    public String adminGetAllTR(HttpSession session){

        Admin admin = (Admin)session.getAttribute("admin");
        if(admin==null)return "redirect:/adminLogin";

        String res = tradeRecordsService.adminGetAll(admin,session);
        System.out.println("res-adminGetAllTR: "+res);
        if(!res.equals("success")){
            return "404";
        }

        return "redirect:/admin-seeAllTR";
    }

    @ResponseBody
    @RequestMapping("admin-deleteOneTR.do")
    public String adminDeleteOneTR(String orderFormID,String payerID,String receiverID,HttpSession session){
        Admin admin = (Admin)session.getAttribute("admin");
        if(admin==null)return "请先登录";
        String res = tradeRecordsService.adminDeleteOneTR(admin,orderFormID,payerID,receiverID,session);
        System.out.println("res-adminDeleteOneTR: "+res);

        return res;
    }
}
